﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ArmyCreator.ViewModels
{
    public class CategoryViewModel : ALoadable<DataModel.Category>, INotifyPropertyChanged
    {
        private string name;

        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                NotifyPropertyChanged("Name");
            }
        }

        public ObservableCollection<UnitViewModel> Units { get; set; }

        public CategoryViewModel()
        {
            Units = new ObservableCollection<UnitViewModel>();
        }


        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected override void Load(DataModel.Category model, int depth)
        {
            this.Name = model.Name;

            if (model.Scouads != null)
            {
                foreach (var scouad in model.Scouads)
                {
                    UnitViewModel unitViewModel = new UnitViewModel();
                    unitViewModel.LoadData(scouad, depth - 1);
                    this.Units.Add(unitViewModel);
                }
            }
        }
    }
}
